"""
@author: ty
@file: 2022-11-24zuoye.py
@time: 2022/11/24 19:06
"""

import os


def pytree(path, depth=0):
    if depth == 0:
        print(path)

        # 循环输出路径下面所有的文件夹和文件
    for file in os.listdir(path):
        print("|    " * depth, end="")
        print("|----", file)
        print(path)

        #用 + 拼接成绝对路径
        files = path + "\\" + file

        # 判断是否为文件夹，是的话递归调用自己
        if os.path.isdir(files):
            pytree(files, depth + 1)
        else:
            print("|----", file)

pytree("D:/sanchuang/python/python project/2022-11-24模块和包")



